package com.jxc.action.xtpz;

import org.apache.log4j.Logger;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;

import com.jxc.action.BaseAction;
import com.jxc.model.vo.Json;
import com.jxc.model.vo.VBasicArgument;
import com.jxc.service.BasicArgumentServiceI;
import com.jxc.util.ExceptionUtil;
import com.opensymphony.xwork2.ModelDriven;

@Namespace("/xtpz")
@Action(value = "basicArgumentAction", results = { @Result(name = "basicArgument", location = "/basicArgument/basicArgument.jsp"),
		@Result(name = "basicArgumentEdit", location = "/basicArgument/basicArgumentEdit.jsp") })
public class BasicArgumentAction extends BaseAction implements ModelDriven<VBasicArgument> {
	private final static Logger logger = Logger.getLogger(BasicArgumentAction.class);
	@Autowired
	private BasicArgumentServiceI basicArgumentService;

	private VBasicArgument model = new VBasicArgument();

	@Override
	public VBasicArgument getModel() {
		return model;
	}

	public String basicArgument() {
		getSubAuths("XTPZ_JCXXPZ");
		return "basicArgument";
	}

	public void datagrid() {
		writeJson(basicArgumentService.datagrid(model));
	}

	public String basicArgumentEdit() {
		return "basicArgumentEdit";
	}

	public void edit() {
		Json j = new Json();
		try {
			basicArgumentService.update(model);
			j.setMsg("修改成功！");
			j.setSuccess(true);
		} catch (Exception e) {
			j.setMsg("修改失败！");
			logger.info(ExceptionUtil.getExceptionMessage(e));
		}
		super.writeJson(j);
	}
}
